class CreateCategoryNames < ActiveRecord::Migration
  def self.up
    create_table :category_names do |t|
      t.references :category
      t.text :name
      t.string :language

      t.timestamps
    end
    
    Category.find(:all).each do |cat|
      CategoryName.create :category_id => cat.id, :language => 'English', :name => cat.old_name
    end
    
    remove_column(:categories, :name)
  end

  def self.down
    add_column(:categories, :name, :string)
    
    CategoryName.find(:all, :conditions => {:language => 'English'}).each do |cat_name|
      cat = cat_name.category
      cat.name = cat_name.name
      cat.save!
    end
    
    drop_table :category_names
  end
end